/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package teste;

import java.io.File;
import java.io.PrintWriter;
import java.sql.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 *
 * @author Wenderson
 */
public class ManipulaArquivo {
    
    public static boolean inserirArquivo(String conteudo) {
        verificaDiretorio("TESTE");
        
        try {
            DateFormat df = new SimpleDateFormat("dd-MM-yyyy hh-mm-ss");
            String data = df.format(Calendar.getInstance().getTime());
            
            String nomefile = "TESTE\\Testes " + data + " hrs.txt";
            
            System.out.println(nomefile);
            
            File file = new File(nomefile);
            
            if (!file.exists()) {
                file.createNewFile();
            }
            
            PrintWriter pw = new PrintWriter(file);
            pw.println(conteudo);
            
            pw.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
    
    
    
    private static void verificaDiretorio(String diretorio) {
        try {
            File dir = new File(diretorio);
            
            if (!dir.exists()) {
                dir.mkdir();
            }
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public static void main(String[] args) {
        ManipulaArquivo.inserirArquivo("TESTE");
    }
}
